﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChessOnline
{
    public enum Direction
    {
        North,
        NorthEast,
        East,
        SouthEast,
        South,
        SouthWest,
        West,
        NorthWest
    };
    /// <summary>
    /// Определяет возможные пути хода фигуры
    /// </summary>
    class Path
    {
        private List<Coordinate> _path = new List<Coordinate>();

        public List<Coordinate> path
        {
            get { return _path; }
            set { _path = value; }
        }
        /// <summary>
        /// Просчитывает путь пешки 
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="color">Цвет пешки</param>
        /// <param name="gB">Игровое поле с фигурами</param>
        public void PathPawn(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            var dic = gB.GetDicCells();
            if (color == ChessColor.White)
            {
                if (figureCoordinate.Number == 2)
                {
                    if (dic[figureCoordinate.NextUp()].FigureType == ChessType.None)
                    {
                        path.Add(figureCoordinate.NextUp());
                        if ( dic[figureCoordinate.NextUp().NextUp()].FigureType == ChessType.None)
                            path.Add(figureCoordinate.NextUp().NextUp());
                    }
                    
                }
                else
                    if ( dic[figureCoordinate.NextUp()].FigureType == ChessType.None)
                        path.Add(figureCoordinate.NextUp());

                //Рассмотрение на сруб фигуры на северо-восток
                if (figureCoordinate.Number < 8 && figureCoordinate.Literal < LiteralCoord.h)
                {                  
                    if (dic[figureCoordinate.NextUp().NextRight()].FigureType != ChessType.None)  //Если есть фигура в клетке по диагонали
                        if (dic[figureCoordinate.NextUp().NextRight()].findOutChessColor() == ChessColor.Black) //Если она черного цвета
                            path.Add(figureCoordinate.NextUp().NextRight());
                }
                //Рассмотрение на сруб фигуры на северо-запад
                if (figureCoordinate.Number < 8 && figureCoordinate.Literal > LiteralCoord.a)
                {
                    if (dic[figureCoordinate.NextUp().NextLeft()].FigureType != ChessType.None)
                        if (dic[figureCoordinate.NextUp().NextLeft()].findOutChessColor() == ChessColor.Black)
                            path.Add(figureCoordinate.NextUp().NextLeft());
                }
 
            }
            else
            {//BlackPawn
                if (figureCoordinate.Number == 7)
                {
                    if (dic[figureCoordinate.NextDown()].FigureType == ChessType.None)
                    {
                        path.Add(figureCoordinate.NextDown());
                        if (dic[figureCoordinate.NextDown().NextDown()].FigureType == ChessType.None)
                            path.Add(figureCoordinate.NextDown().NextDown());
                    }
                }
                else
                    if (dic[figureCoordinate.NextDown()].FigureType == ChessType.None)
                        path.Add(figureCoordinate.NextDown());

                //Рассмотрение возможности сруба на юго-восток
                if (figureCoordinate.Number > 1 && figureCoordinate.Literal < LiteralCoord.h)
                {
                    if (dic[figureCoordinate.NextDown().NextRight()].FigureType != ChessType.None)
                        if (dic[figureCoordinate.NextDown().NextRight()].findOutChessColor() == ChessColor.White)
                            path.Add(figureCoordinate.NextDown().NextRight());
                }
                //Рассмотрение возможности сруба на юго-запад
                if (figureCoordinate.Number > 1 && figureCoordinate.Literal > LiteralCoord.a)
                {
                    if (dic[figureCoordinate.NextDown().NextLeft()].FigureType != ChessType.None)
                        if (dic[figureCoordinate.NextDown().NextLeft()].findOutChessColor() == ChessColor.White)
                            path.Add(figureCoordinate.NextDown().NextLeft());
                }
            }

            WillBeCheck(figureCoordinate, color, gB);
        }

        private void WillBeCheck(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            var BoardDict = gB.GetDicCells();
            GameBoard BoardCopy = new GameBoard();
            BoardCopy.SetCellsFromDictionary(BoardDict);
            for (int i = 0; i < path.Count; i++)
            {
                Coordinate new_coord = path[i];
                ChessType tmp = BoardDict[new_coord].FigureType;
                BoardDict[new_coord].FigureType = BoardDict[figureCoordinate].FigureType;
                BoardDict[figureCoordinate].FigureType = ChessType.None;
                BoardCopy.SetCellsFromDictionary(BoardDict);
                var CheckedPaths = BuildCheckPass(color, BoardCopy);
                BoardDict[figureCoordinate].FigureType = BoardDict[new_coord].FigureType;
                BoardDict[new_coord].FigureType = tmp;
                BoardCopy.SetCellsFromDictionary(BoardDict);
                if (CheckedPaths.Count > 0)
                {                   
                    path.Remove(path[i]);
                    i = -1;
                }

            }
        }

        /// <summary>
        /// Просчитывает возможный ход Ферзя во всех направлениях
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение ферзя</param>
        /// <param name="color">Цвет ферзя</param>
        /// <param name="gB">Текущая игровая доска</param>
        public void PathQueen(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            PathQueen(figureCoordinate, color, Direction.North, gB);
            PathQueen(figureCoordinate, color, Direction.NorthEast, gB);
            PathQueen(figureCoordinate, color, Direction.East, gB);
            PathQueen(figureCoordinate, color, Direction.SouthEast, gB);
            PathQueen(figureCoordinate, color, Direction.South, gB);
            PathQueen(figureCoordinate, color, Direction.SouthWest, gB);
            PathQueen(figureCoordinate, color, Direction.West, gB);
            PathQueen(figureCoordinate, color, Direction.NorthWest, gB);
            WillBeCheck(figureCoordinate, color, gB);
        }

        /// <summary>
        /// Просчитывает путь ферзя в указанном направлении 
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="direction">Направление пути (из 8)</param>
        private void PathQueen(Coordinate figureCoordinate, ChessColor color, Direction direction, GameBoard gB)
        {
            List<Coordinate> localList = new List<Coordinate>();
            switch (direction)
            {
                case Direction.North: //вверх
                    localList = UpPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.NorthEast:
                    localList = NorthEastPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.East: //вправо
                    localList = RightPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.SouthEast: //юго-восток
                    localList = SouthEastPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.South:
                    localList = DownPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.SouthWest:
                    localList = SouthWestPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.West:
                    localList = LeftPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.NorthWest:
                    localList = NorthWestPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
            }
            AddToGlPath(localList);
        }


        /// <summary>
        /// Просчитывает возможный ход ладьи во всех направлениях
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="gB">Текущая игровая доска</param>
        public void PathRook(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            PathRook(figureCoordinate, color, Direction.North, gB);
            PathRook(figureCoordinate, color, Direction.East, gB);
            PathRook(figureCoordinate, color, Direction.South, gB);
            PathRook(figureCoordinate, color, Direction.West, gB);
            WillBeCheck(figureCoordinate, color, gB);
        }

        /// <summary>
        /// Просчитывает путь ладьи в указанном направлении 
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="direction">Направление пути (из 4)</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="gB">Текущая игровая доска</param>
        private void PathRook(Coordinate figureCoordinate,ChessColor color, Direction direction, GameBoard gB)
        {
            List<Coordinate> localList = new List<Coordinate>();
            switch (direction)
            {
                case Direction.North: //Вверх
                    localList = UpPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.East: //Вправо
                    localList = RightPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.South: //Вниз
                    localList = DownPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.West: //Влево
                    localList = LeftPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
            }
            AddToGlPath(localList);
        }

        private void AddToGlPath(List<Coordinate> localList)
        {
            foreach (Coordinate coord in localList)
                path.Add(coord);
        }
        
        private List<Coordinate> ExcludePath(List<Coordinate> localList, ChessColor color, GameBoard game)
        {
            List<Coordinate> lst = localList;
            var dictGame = game.GetDicCells();
            bool ToDelete = false;
            for (int i = 0; i < lst.Count; i++)
            {
                if (ToDelete)
                {
                    lst.Remove(lst[i]);
                    i -= 1;
                }
                else
                {
                    if (dictGame[lst[i]].FigureType != ChessType.None)
                    {
                        ToDelete = true;
                        if (dictGame[lst[i]].findOutChessColor() == color)
                        {
                            lst.Remove(lst[i]);
                            i -= 1;
                        }
                    }
                }
            }
            return lst;
        }

        /// <summary>
        /// Просчитывает возможный ход слона во всех направлениях
        /// </summary>
        /// <param name="figureCoordinate">Текущая координата фигуры</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="gB">Игровая доска</param>
        public void PathBishop(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            PathBishop(figureCoordinate, color, Direction.NorthEast, gB);
            PathBishop(figureCoordinate, color, Direction.SouthEast, gB);
            PathBishop(figureCoordinate, color, Direction.SouthWest, gB);
            PathBishop(figureCoordinate, color, Direction.NorthWest, gB);
            WillBeCheck(figureCoordinate, color, gB);
        }

        /// <summary>
        /// Просчитывает путь слона в указанном направлении 
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="direction">Направление пути (из 4)</param>
        /// <param name="gB">Текущая игровая доска</param>
        private void PathBishop(Coordinate figureCoordinate, ChessColor color, Direction direction, GameBoard gB)
        {
            List<Coordinate> localList = new List<Coordinate>();
            switch (direction)
            {
                case Direction.NorthEast: //северо-восток
                    localList = NorthEastPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.SouthEast: //юго-восток
                    localList = SouthEastPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.SouthWest:
                    localList = SouthWestPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
                case Direction.NorthWest:
                    localList = NorthWestPath(figureCoordinate);
                    localList = ExcludePath(localList, color, gB);
                    break;
            }
            AddToGlPath(localList);
        }

        /// <summary>
        /// Просчитывает все пути коня с учетом стоящих на пути фигурах
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="gB">Текущее состояние игровой доски</param>
        public void PathKnight(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            PathKnight(figureCoordinate,color,Direction.North, gB);
            PathKnight(figureCoordinate, color, Direction.NorthEast, gB);
            PathKnight(figureCoordinate, color, Direction.East, gB);
            PathKnight(figureCoordinate, color, Direction.SouthEast, gB);
            PathKnight(figureCoordinate, color, Direction.South, gB);
            PathKnight(figureCoordinate, color, Direction.SouthWest, gB);
            PathKnight(figureCoordinate, color, Direction.West, gB);
            PathKnight(figureCoordinate, color, Direction.NorthWest, gB);
            WillBeCheck(figureCoordinate, color, gB);
        }

        /// <summary>
        /// Просчитывает путь коня в указанном направлении 
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="direction">Направление пути (из 8)</param>
        private void PathKnight(Coordinate figureCoordinate, ChessColor color, Direction direction, GameBoard gB)
        {
            var gameDictionary = gB.GetDicCells();
            switch (direction)
            {   
                case Direction.North: //UUR (1)
                    if (figureCoordinate.Number < 7 && figureCoordinate.Literal != LiteralCoord.h)
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextUp().NextRight()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextUp().NextUp().NextRight());
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextUp().NextRight()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextUp().NextUp().NextRight());
                    }
                    break;
                case Direction.NorthEast: //URR (2)
                    if( figureCoordinate.Number < 8 && figureCoordinate.Literal < LiteralCoord.g)
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextRight().NextRight()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextUp().NextRight().NextRight());
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextRight().NextRight()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextUp().NextRight().NextRight());
                    }
                    break;
                case Direction.East: //RRD (4)
                    if (figureCoordinate.Number > 1 && figureCoordinate.Literal < LiteralCoord.g)
                    {
                        if (gameDictionary[figureCoordinate.NextRight().NextRight().NextDown()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextRight().NextRight().NextDown());
                        }
                        else if (gameDictionary[figureCoordinate.NextRight().NextRight().NextDown()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextRight().NextRight().NextDown());
                    }
                    break;
                case Direction.SouthEast: //RDD (5)
                    if (figureCoordinate.Number > 2 && figureCoordinate.Literal < LiteralCoord.h)
                    {
                        if (gameDictionary[figureCoordinate.NextRight().NextDown().NextDown()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextRight().NextDown().NextDown());
                        }
                        else if (gameDictionary[figureCoordinate.NextRight().NextDown().NextDown()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextRight().NextDown().NextDown());
                    }
                    break;
                case Direction.South: //DDL (7)
                    if (figureCoordinate.Number > 2 && figureCoordinate.Literal > LiteralCoord.a)
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextDown().NextLeft()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextDown().NextDown().NextLeft());
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextDown().NextLeft()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextDown().NextDown().NextLeft());
                    }
                    break;
                case Direction.SouthWest: //DLL(8)
                    if (figureCoordinate.Number > 1 && figureCoordinate.Literal > LiteralCoord.b)
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextLeft().NextLeft()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextDown().NextLeft().NextLeft());
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextLeft().NextLeft()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextDown().NextLeft().NextLeft());
                    }
                    break;
                case Direction.West: //LLU(10)
                    if (figureCoordinate.Number < 8 && figureCoordinate.Literal > LiteralCoord.b)
                    {
                        if (gameDictionary[figureCoordinate.NextLeft().NextLeft().NextUp()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextLeft().NextLeft().NextUp());
                        }
                        else if (gameDictionary[figureCoordinate.NextLeft().NextLeft().NextUp()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextLeft().NextLeft().NextUp());
                    }
                    break;
                case Direction.NorthWest: //LUU(11)
                    if (figureCoordinate.Number < 7 && figureCoordinate.Literal > LiteralCoord.a)
                    {
                        if (gameDictionary[figureCoordinate.NextLeft().NextUp().NextUp()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextLeft().NextUp().NextUp());
                        }
                        else if (gameDictionary[figureCoordinate.NextLeft().NextUp().NextUp()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextLeft().NextUp().NextUp());
                    }
                    break;
            }
        }

        /// <summary>
        /// Просчитывает все возможные пути короля
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">Цвет фигуры</param>
        /// <param name="gB">Игровая доска</param>
        public void PathKing(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            PathKing(figureCoordinate, color, Direction.North, gB);
            PathKing(figureCoordinate, color, Direction.NorthEast, gB);
            PathKing(figureCoordinate, color, Direction.East, gB);
            PathKing(figureCoordinate, color, Direction.SouthEast, gB);
            PathKing(figureCoordinate, color, Direction.South, gB);
            PathKing(figureCoordinate, color, Direction.SouthWest, gB);
            PathKing(figureCoordinate, color, Direction.West, gB);
            PathKing(figureCoordinate, color, Direction.NorthWest, gB);
            WillBeCheck(figureCoordinate, color, gB);
        }



        /// <summary>
        /// Просчитывает путь короля в указанном направлении без учета стоящих на пути фигур
        /// </summary>
        /// <param name="figureCoordinate">Текущее положение фигуры</param>
        /// <param name="direction">Направление пути (из 8)</param>
        private void PathKing(Coordinate figureCoordinate, ChessColor color, Direction direction, GameBoard gB)
        {
            var gameDictionary = gB.GetDicCells();
            switch (direction)
            {//граничные случаи ???
                case Direction.North: //вверх
                    if (figureCoordinate.Number < 8)
                    {
                        if (gameDictionary[figureCoordinate.NextUp()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextUp());
                        }
                        else if (gameDictionary[figureCoordinate.NextUp()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextUp());
                    }
                    break;
                case Direction.NorthEast: //северо-восток
                    if (!figureCoordinate.AtTheTopEdge() && !figureCoordinate.AtTheRightEdge())
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextRight()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextUp().NextRight());
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextRight()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextUp().NextRight());
                    }
                    break;
                case Direction.East: //вправо
                    if (figureCoordinate.Literal != LiteralCoord.h)
                    {
                        if (gameDictionary[figureCoordinate.NextRight()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextRight());
                        }
                        else if (gameDictionary[figureCoordinate.NextRight()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextRight());
                    }
                    break;
                case Direction.SouthEast: //юго-восток
                    if (!figureCoordinate.AtTheRightEdge() && !figureCoordinate.AtTheBottomEdge())
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextRight()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextDown().NextRight());
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextRight()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextDown().NextRight());
                    }
                    break;
                case Direction.South: //Вниз
                    if (figureCoordinate.Number > 1)
                    {
                        if (gameDictionary[figureCoordinate.NextDown()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextDown());
                        }
                        else if (gameDictionary[figureCoordinate.NextDown()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextDown());
                    }
                    break;
                case Direction.SouthWest: //юго-запад
                    if (!figureCoordinate.AtTheBottomEdge() && !figureCoordinate.AtTheLeftEdge())
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextLeft()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextDown().NextLeft());
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextLeft()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextDown().NextLeft());
                    }
                    break;
                case Direction.West: //влево
                    if (figureCoordinate.Literal > LiteralCoord.a)
                    {
                        if (gameDictionary[figureCoordinate.NextLeft()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextLeft());
                        }
                        else if (gameDictionary[figureCoordinate.NextLeft()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextLeft());
                    }
                    break;
                case Direction.NorthWest: //северо-запад
                    if (!figureCoordinate.AtTheTopEdge() && !figureCoordinate.AtTheLeftEdge())
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextLeft()].FigureType == ChessType.None)
                        {
                            path.Add(figureCoordinate.NextUp().NextLeft());
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextLeft()].findOutChessColor() != color)
                            path.Add(figureCoordinate.NextUp().NextLeft());
                    }
                    break;
            }
        }


        private List<Coordinate> NorthWestPath(Coordinate figureCoordinate)
        {
            //северо-запад
            Coordinate tmp = figureCoordinate;
            List<Coordinate> localPath = new List<Coordinate>();
            if (!tmp.AtTheLeftEdge() && !tmp.AtTheTopEdge())
            {
                tmp = tmp.NextUp().NextLeft();
                while (!tmp.AtTheLeftEdge() && !tmp.AtTheTopEdge()) 
                {
                    localPath.Add(tmp);
                    tmp = tmp.NextUp().NextLeft();
                }
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> LeftPath(Coordinate figureCoordinate)
        {
            List<Coordinate> localPath = new List<Coordinate>();
            Coordinate tmp = figureCoordinate;
            for (int i = (int)figureCoordinate.Literal - 1; i >= (int)LiteralCoord.a; i--)
            {
                tmp = tmp.NextLeft();
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> SouthWestPath(Coordinate figureCoordinate)
        {
            //юго-запад
            Coordinate tmp = figureCoordinate;
            List<Coordinate> localPath = new List<Coordinate>();
            if (!tmp.AtTheLeftEdge() && !tmp.AtTheBottomEdge())
            {
                tmp = tmp.NextDown().NextLeft();
                while (!tmp.AtTheLeftEdge() && !tmp.AtTheBottomEdge())
                {
                    localPath.Add(tmp);
                    tmp = tmp.NextDown().NextLeft();
                }
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> DownPath(Coordinate figureCoordinate)
        {
            List<Coordinate> localPath = new List<Coordinate>();
            Coordinate tmp = figureCoordinate;
            for (int i = figureCoordinate.Number - 1; i >= 1; i--)
            {
                tmp = tmp.NextDown();
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> SouthEastPath(Coordinate figureCoordinate)
        {
            Coordinate tmp = figureCoordinate;
            List<Coordinate> localPath = new List<Coordinate>();
            if (!tmp.AtTheRightEdge() && !tmp.AtTheBottomEdge())
            {
                tmp = tmp.NextDown().NextRight();
                while (!tmp.AtTheRightEdge() && !tmp.AtTheBottomEdge()) 
                {
                    localPath.Add(tmp);
                    tmp = tmp.NextDown().NextRight();
                }
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> RightPath(Coordinate figureCoordinate)
        {
            List<Coordinate> localPath = new List<Coordinate>();
            Coordinate tmp = figureCoordinate;
            for (int i = (int)figureCoordinate.Literal + 1; i <= (int)LiteralCoord.h; i++)
            {
                tmp = tmp.NextRight();
                localPath.Add(tmp);             
            }
            return localPath;
        }

        private List<Coordinate> NorthEastPath(Coordinate figureCoordinate)
        {
            //северо-восток
            Coordinate tmp = figureCoordinate;
            List<Coordinate> localPath = new List<Coordinate>();
            if (!tmp.AtTheRightEdge() && !tmp.AtTheTopEdge())     //Если не на правой и не на верхней границе
            {
                tmp = tmp.NextUp().NextRight();      //Сдвигаемся по диагонали
                while (!tmp.AtTheRightEdge() && !tmp.AtTheTopEdge()) 
                {
                    localPath.Add(tmp);
                    tmp = tmp.NextUp().NextRight();
                }
                localPath.Add(tmp);
            }
            return localPath;
        }

        private List<Coordinate> UpPath(Coordinate figureCoordinate)
        {
            List<Coordinate> localPath = new List<Coordinate>();
            Coordinate tmp = figureCoordinate;
            for (int i = figureCoordinate.Number + 1; i <= 8; i++)
            {
                tmp = tmp.NextUp();
                localPath.Add(tmp);   
            }
            return localPath;
        }

        /// <summary>
        /// По вертикали и горизонтали слон, пешка и конь не ставят шах
        /// </summary>
        /// <param name="cell">Ячейка с фигурой от которой предположительно ставится шах</param>
        /// <returns></returns>
        private bool NotACheckHorUp(GameCell cell)
        {
            return (cell.FigureType != ChessType.WhiteBishop &&
                    cell.FigureType != ChessType.WhitePawn &&
                    cell.FigureType != ChessType.WhiteKnight &&
                    cell.FigureType != ChessType.BlackBishop &&
                    cell.FigureType != ChessType.BlackPawn &&
                    cell.FigureType != ChessType.BlackKnight);
        }

        /// <summary>
        /// По северным диагоналям не ставят шах конь, ладья и черная пешка
        /// </summary>
        /// <param name="cell"></param>
        /// <returns></returns>
        private bool NotACheckNorthDiag(GameCell cell)
        {
            return (cell.FigureType != ChessType.WhiteKnight &&
                    cell.FigureType != ChessType.WhiteRook &&
                    cell.FigureType != ChessType.BlackKnight &&
                    cell.FigureType != ChessType.BlackPawn &&
                    cell.FigureType != ChessType.BlackRook);
       
        }

        private bool NotACheckSouthDiag(GameCell cell)
        {
            return (cell.FigureType != ChessType.WhiteKnight &&
                    cell.FigureType != ChessType.WhitePawn &&
                    cell.FigureType != ChessType.WhiteRook &&
                    cell.FigureType != ChessType.BlackKnight &&
                    cell.FigureType != ChessType.BlackRook);
        }
        /// <summary>
        /// Определяет состояние шаха
        /// </summary>
        /// <param name="active_chess_color">Цвет только что сходившего игрока</param>
        /// <param name="gb">Текущая игровая доска</param>
        /// <returns>Список путей по которым идет шах (List<list<>>)</returns>
        public /*static*/ List<List<Coordinate>> BuildCheckPass(ChessColor active_chess_color, GameBoard GB)
        {
            List<List<Coordinate>> CheckedPaths = new List<List<Coordinate>>();

            ChessType CheckedKing = (active_chess_color == ChessColor.White) ? ChessType.WhiteKing : ChessType.BlackKing;
            ChessColor KingColor = active_chess_color;

            var BoardDic = GB.GetDicCells();
            Coordinate KingCoordinate = new Coordinate();
            foreach (var cell in BoardDic)
            {
                if (cell.Value.FigureType == CheckedKing)
                    KingCoordinate = cell.Value.Coord;
            }

            List<Coordinate> singlePath = new List<Coordinate>();
            singlePath = UpPath(KingCoordinate);
            singlePath = ExcludePath(singlePath, KingColor, GB);
            if (singlePath.Count > 0)
                if (BoardDic[singlePath[singlePath.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath[singlePath.Count - 1]].findOutChessColor() != KingColor)
                        if (NotACheckHorUp( BoardDic[singlePath[singlePath.Count - 1]]))
                            CheckedPaths.Add(singlePath);

            List<Coordinate> singlePath1 = new List<Coordinate>();
            singlePath1 = NorthEastPath(KingCoordinate);
            singlePath1 = ExcludePath(singlePath1, KingColor, GB);
            if (singlePath1.Count > 0)
                if (BoardDic[singlePath1[singlePath1.Count - 1]].FigureType != ChessType.None)
                        if (BoardDic[singlePath1[singlePath1.Count - 1]].findOutChessColor() != KingColor)
                            if (NotACheckNorthDiag (BoardDic[singlePath1[singlePath1.Count - 1]]))
                                CheckedPaths.Add(singlePath1);

            List<Coordinate> singlePath2 = new List<Coordinate>();
            singlePath2 = RightPath(KingCoordinate);
            singlePath2 = ExcludePath(singlePath2, KingColor, GB);
            if (singlePath2.Count > 0)
                if (BoardDic[singlePath2[singlePath2.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath2[singlePath2.Count - 1]].findOutChessColor() != KingColor)
                        if (NotACheckHorUp(BoardDic[singlePath2[singlePath2.Count - 1]]))
                            CheckedPaths.Add(singlePath2);

            List<Coordinate> singlePath3 = new List<Coordinate>();
            singlePath3 = SouthEastPath(KingCoordinate);
            singlePath3 = ExcludePath(singlePath3, KingColor, GB);
            if (singlePath3.Count > 0)
                if (BoardDic[singlePath3[singlePath3.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath3[singlePath3.Count - 1]].findOutChessColor() != KingColor)
                        if (NotACheckSouthDiag (BoardDic[singlePath3[singlePath3.Count - 1]]))
                            CheckedPaths.Add(singlePath3);

            List<Coordinate> singlePath4 = new List<Coordinate>();
            singlePath4 = DownPath(KingCoordinate);
            singlePath4 = ExcludePath(singlePath4, KingColor, GB);
            if (singlePath4.Count > 0)
                if (BoardDic[singlePath4[singlePath4.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath4[singlePath4.Count - 1]].findOutChessColor() != KingColor)  
                        if (NotACheckHorUp (BoardDic[singlePath4[singlePath4.Count - 1]]))
                            CheckedPaths.Add(singlePath4);

            List<Coordinate> singlePath5 = new List<Coordinate>();
            singlePath5 = SouthWestPath(KingCoordinate);
            singlePath5 = ExcludePath(singlePath5, KingColor, GB);
            if (singlePath5.Count > 0)
                if (BoardDic[singlePath5[singlePath5.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath5[singlePath5.Count - 1]].findOutChessColor() != KingColor)
                        if( NotACheckSouthDiag (BoardDic[singlePath5[singlePath5.Count - 1]]))
                            CheckedPaths.Add(singlePath5);

            List<Coordinate> singlePath6 = new List<Coordinate>();
            singlePath6 = LeftPath(KingCoordinate);
            singlePath6 = ExcludePath(singlePath6, KingColor, GB);
            if (singlePath6.Count > 0)
                if (BoardDic[singlePath6[singlePath6.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath6[singlePath6.Count - 1]].findOutChessColor() != KingColor)
                        if(NotACheckHorUp(BoardDic[singlePath6[singlePath6.Count - 1]]))
                            CheckedPaths.Add(singlePath6);

            List<Coordinate> singlePath7 = new List<Coordinate>();
            singlePath7 = NorthWestPath(KingCoordinate);
            singlePath7 = ExcludePath(singlePath7, KingColor, GB);
            if (singlePath7.Count > 0)
                if (BoardDic[singlePath7[singlePath7.Count - 1]].FigureType != ChessType.None)
                    if (BoardDic[singlePath7[singlePath7.Count - 1]].findOutChessColor() != KingColor)
                        if (NotACheckNorthDiag(BoardDic[singlePath7[singlePath7.Count - 1]]))
                            CheckedPaths.Add(singlePath7);

            List<Coordinate> LikeAKnight = CheckKnight(KingCoordinate, KingColor, GB);

            foreach (var coord in LikeAKnight)
            {
                List<Coordinate> singleKnightPath = new List<Coordinate>();
                if (BoardDic[coord].FigureType != ChessType.None)
                    if (BoardDic[coord].findOutChessColor() != KingColor)
                    {
                        singleKnightPath.Add(coord);
                        CheckedPaths.Add(singleKnightPath);
                    }
            }

            return CheckedPaths;
        }

        /// <summary>
        /// Определяет возможный ход ферзя в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathQueen(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathQueen(figureCoordinate, color, gB);

            ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// Определяет возможный ход слона в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathBishop(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathBishop(figureCoordinate, color, gB);

            ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// Определяет возможный ход ладьи в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathRook(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathRook(figureCoordinate, color, gB);

            ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// Определяет возможный ход коня в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathKnight(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathKnight(figureCoordinate, color, gB);

            ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// Определяет возможный ход пешки в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathPawn(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathPawn(figureCoordinate, color, gB);

            ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// Определяет возможный ход короля в состоянии шаха
        /// </summary>
        /// <param name="figureCoordinate">текущая координата фигуры</param>
        /// <param name="color">цвет фигуры</param>
        /// <param name="gB">положение игровой доски</param>
        /// <param name="CheckedPaths">Пути, по которым шах королю</param>
        public void CheckedPathKing(Coordinate figureCoordinate, ChessColor color, GameBoard gB, List<List<Coordinate>> CheckedPaths)
        {
            PathKing(figureCoordinate, color, gB);

            foreach (List<Coordinate> lst in CheckedPaths)
                for (int i = 0; i < path.Count; i++)
                //foreach (Coordinate coord in path)
                    if (lst.Contains(path[i]))                 ////////!!!!!!!!!!!!!!!!!
                    {
                        path.Remove(path[i]);
                        i = -1;
                    }


            List<Coordinate> figurePath = new List<Coordinate>();
            var GameDic = gB.GetDicCells();
            foreach (List<Coordinate> lst in CheckedPaths)
            {
                if (lst.Count > 0)
                    switch (GameDic[lst[lst.Count - 1]].FigureType)
                    {
                        case ChessType.BlackBishop:
                            if ( Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthEast)
                                figurePath = NorthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthWest)
                                figurePath = NorthWestPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthEast)
                                figurePath = SouthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthWest)
                                figurePath = SouthWestPath(lst[lst.Count - 1]);
                            break;
                        case ChessType.BlackQueen:
                            if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.North)
                                figurePath = UpPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthEast)
                                figurePath = NorthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.East)
                                figurePath = RightPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthEast)
                                figurePath = SouthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.South)
                                figurePath = DownPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthWest)
                                figurePath = SouthWestPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.West)
                                figurePath = LeftPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthWest)
                                figurePath = NorthWestPath(lst[lst.Count - 1]);
                            break;
                        case ChessType.BlackRook:
                            if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.North)
                                figurePath = UpPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.East)
                                figurePath = RightPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.South)
                                figurePath = DownPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.West)
                                figurePath = LeftPath(lst[lst.Count - 1]);
                            break;
                        case ChessType.WhiteBishop:
                            if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthEast)
                                figurePath = NorthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthWest)
                                figurePath = NorthWestPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthEast)
                                figurePath = SouthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthWest)
                                figurePath = SouthWestPath(lst[lst.Count - 1]);
                            break;
                        case ChessType.WhiteQueen:
                            if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.North)
                                figurePath = UpPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthEast)
                                figurePath = NorthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.East)
                                figurePath = RightPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthEast)
                                figurePath = SouthEastPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.South)
                                figurePath = DownPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.SouthWest)
                                figurePath = SouthWestPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.West)
                                figurePath = LeftPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.NorthWest)
                                figurePath = NorthWestPath(lst[lst.Count - 1]);
                            break;
                        case ChessType.WhiteRook:
                            if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.North)
                                figurePath = UpPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.East)
                                figurePath = RightPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.South)
                                figurePath = DownPath(lst[lst.Count - 1]);
                            else if (Coordinate.FindOutDirection(lst[lst.Count - 1], figureCoordinate) == Direction.West)
                                figurePath = LeftPath(lst[lst.Count - 1]);
                            break;
                    }
            }

            for (int i = 0; i < path.Count; i++)
            //foreach (Coordinate coord in path)
                if (figurePath.Contains(path[i]))
                {
                    path.Remove(path[i]);
                    i = -1;
                }


            //ExcludeChecked(CheckedPaths);
        }

        /// <summary>
        /// удаляет возможные координаты хода в случае состояния шаха
        /// </summary>
        /// <param name="CheckedPaths">Пути шаха</param>
        private void ExcludeChecked(List<List<Coordinate>> CheckedPaths)
        {
            if (CheckedPaths.Count == 1)
                for (int i = 0; i < path.Count; i++)
                //foreach (Coordinate coord in path)
                {
                    if (!CheckedPaths[0].Contains(path[i]))
                    {
                        path.Remove(path[i]);
                        i=-1;
                    }
                }
            else if (CheckedPaths.Count > 1)
                path.Clear();
        }

        private Coordinate CheckKnight(Coordinate figureCoordinate, ChessColor color, Direction direction, GameBoard gB)
        {
            Coordinate ToReturn = new Coordinate();
            var gameDictionary = gB.GetDicCells();
            switch (direction)
            {
                case Direction.North: //UUR (1)
                    if (figureCoordinate.Number < 7 && figureCoordinate.Literal != LiteralCoord.h)
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextUp().NextRight()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextUp().NextUp().NextRight();
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextUp().NextRight()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextUp().NextUp().NextRight();
                    }
                    break;
                case Direction.NorthEast: //URR (2)
                    if (figureCoordinate.Number < 8 && figureCoordinate.Literal < LiteralCoord.g)
                    {
                        if (gameDictionary[figureCoordinate.NextUp().NextRight().NextRight()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextUp().NextRight().NextRight();
                        }
                        else if (gameDictionary[figureCoordinate.NextUp().NextRight().NextRight()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextUp().NextRight().NextRight();
                    }
                    break;
                case Direction.East: //RRD (4)
                    if (figureCoordinate.Number > 1 && figureCoordinate.Literal < LiteralCoord.g)
                    {
                        if (gameDictionary[figureCoordinate.NextRight().NextRight().NextDown()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextRight().NextRight().NextDown();
                        }
                        else if (gameDictionary[figureCoordinate.NextRight().NextRight().NextDown()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextRight().NextRight().NextDown();
                    }
                    break;
                case Direction.SouthEast: //RDD (5)
                    if (figureCoordinate.Number > 2 && figureCoordinate.Literal < LiteralCoord.h)
                    {
                        if (gameDictionary[figureCoordinate.NextRight().NextDown().NextDown()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextRight().NextDown().NextDown();
                        }
                        else if (gameDictionary[figureCoordinate.NextRight().NextDown().NextDown()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextRight().NextDown().NextDown();
                    }
                    break;
                case Direction.South: //DDL (7)
                    if (figureCoordinate.Number > 2 && figureCoordinate.Literal > LiteralCoord.a)
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextDown().NextLeft()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextDown().NextDown().NextLeft();
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextDown().NextLeft()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextDown().NextDown().NextLeft();
                    }
                    break;
                case Direction.SouthWest: //DLL(8)
                    if (figureCoordinate.Number > 1 && figureCoordinate.Literal > LiteralCoord.b)
                    {
                        if (gameDictionary[figureCoordinate.NextDown().NextLeft().NextLeft()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextDown().NextLeft().NextLeft();
                        }
                        else if (gameDictionary[figureCoordinate.NextDown().NextLeft().NextLeft()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextDown().NextLeft().NextLeft();
                    }
                    break;
                case Direction.West: //LLU(10)
                    if (figureCoordinate.Number < 8 && figureCoordinate.Literal > LiteralCoord.b)
                    {
                        if (gameDictionary[figureCoordinate.NextLeft().NextLeft().NextUp()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextLeft().NextLeft().NextUp();
                        }
                        else if (gameDictionary[figureCoordinate.NextLeft().NextLeft().NextUp()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextLeft().NextLeft().NextUp();
                    }
                    break;
                case Direction.NorthWest: //LUU(11)
                    if (figureCoordinate.Number < 7 && figureCoordinate.Literal > LiteralCoord.a)
                    {
                        if (gameDictionary[figureCoordinate.NextLeft().NextUp().NextUp()].FigureType == ChessType.None)
                        {
                            ToReturn = figureCoordinate.NextLeft().NextUp().NextUp();
                        }
                        else if (gameDictionary[figureCoordinate.NextLeft().NextUp().NextUp()].findOutChessColor() != color)
                            ToReturn = figureCoordinate.NextLeft().NextUp().NextUp();
                    }
                    break;
            }

            return ToReturn;
        }

        private List<Coordinate> CheckKnight(Coordinate figureCoordinate, ChessColor color, GameBoard gB)
        {
            List<Coordinate> ToReturn = new List<Coordinate>();
            if (CheckKnight(figureCoordinate, color, Direction.North, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.North, gB));
            if (CheckKnight(figureCoordinate, color, Direction.NorthEast, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.NorthEast, gB));
            if (CheckKnight(figureCoordinate, color, Direction.East, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.East, gB));
            if (CheckKnight(figureCoordinate, color, Direction.SouthEast, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.SouthEast, gB));
            if (CheckKnight(figureCoordinate, color, Direction.South, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.South, gB));
            if (CheckKnight(figureCoordinate, color, Direction.SouthWest, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.SouthWest, gB));
            if (CheckKnight(figureCoordinate, color, Direction.West, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.West, gB));
            if (CheckKnight(figureCoordinate, color, Direction.NorthWest, gB).Number != 0)
                ToReturn.Add(CheckKnight(figureCoordinate, color, Direction.NorthWest, gB));

            return ToReturn;
        }
       
    }
}
